import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

//token的状态同步
export default new Vuex.Store({
    //状态清除
    state: {
		//user
        token: '',
		//admin
		adminInfo:JSON.parse(sessionStorage.getItem("adminInfo")),
		//user
		userInfo: JSON.parse(sessionStorage.getItem("userInfo"))
    },
    mutations: {
		//set
        SET_TOKEN: (state, token) => {
            state.token = token
            localStorage.setItem("token", token)
        },
		
		//设置管理员信息
		SET_ADMININFO: (state, adminInfo) => {
			state.adminInfo = adminInfo
			sessionStorage.setItem("adminInfo", JSON.stringify(adminInfo))
		},
		
		//设置用户信息
		SET_USERINFO: (state, userInfo) => {
			state.userInfo = userInfo
			sessionStorage.setItem("userInfo", JSON.stringify(userInfo))
		},
		
		//清除token
		
		REMOVE_ADMIN: (state) => {
			localStorage.setItem("token", '')
			//管理员
			sessionStorage.setItem("adminInfo", JSON.stringify(''))
			state.adminInfo = {}
		},
		
		REMOVE_INFO: (state) => {
			localStorage.setItem("token", '')
			//用户
			sessionStorage.setItem("userInfo", JSON.stringify(''))
			state.userInfo = {}
		}

		
	},
	//get
	getters: {
		//管理员
		getAdmin: state =>{
			return state.adminInfo
		},
		//用户
		getUser: state => {
			return state.userInfo
		},
		
    },
	
    actions: {},
	
    modules: {
		//menus
	}
})
